# const define
import sys
from singleton import singleton


@singleton
class _Const:
    class ConstError(TypeError):
        pass

    def __setattr__(self, name, value):
        if name in self.__dict__:
            raise self.ConstError("Can't rebind const(%s)" % name)
        if not name.isupper():
            raise self.ConstError("Const name(%s) is not upper" % name)
        self.__dict__[name] = value

    def __delattr__(self, name):
        if name in self.__dict__:
            raise self.ConstError("Can't unbind const(%s)" % name)
        del self.__dict__[name]


sys.modules[__name__] = _Const()
